package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.XingdongjihuaMapper;
import com.example.xinli.dao.ZhengnianlianxiMapper;
import com.example.xinli.domain.entity.Xingdongjihua;
import com.example.xinli.domain.entity.Zhengnianlianxi;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.XingdongjihuaSubmitVo;
import com.example.xinli.domain.vo.ZhengnianlianxiSubmitVo;
import com.example.xinli.service.IXingdongjihuaService;
import com.example.xinli.service.IZhengnianlianxiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class XingdongjihuaServiceImpl extends ServiceImpl<XingdongjihuaMapper, Xingdongjihua> implements IXingdongjihuaService {

    @Autowired
    XingdongjihuaMapper xingdongjihuaMapper;

    @Override
    public ResponseBean getAllUserXingdongjihua(String userId) {
        QueryWrapper<Xingdongjihua> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Xingdongjihua> xingdongjihuaList = xingdongjihuaMapper.selectList(queryWrapper);
        return ResponseBean.success(xingdongjihuaList);
    }

    @Override
    public ResponseBean submitXingdongjihua(XingdongjihuaSubmitVo xingdongjihuaSubmitVo) {
        Xingdongjihua xingdongjihua = new Xingdongjihua();
        xingdongjihua.setUserId(xingdongjihuaSubmitVo.getUserId());
        xingdongjihua.setDate(xingdongjihuaSubmitVo.getDate());
        xingdongjihua.setJihuaName(xingdongjihuaSubmitVo.getJihuaName());
        xingdongjihua.setLingyu(xingdongjihuaSubmitVo.getLingyu());
        xingdongjihua.setJiazhi(xingdongjihuaSubmitVo.getJiazhi());
        xingdongjihua.setYitu(xingdongjihuaSubmitVo.getYitu());
        xingdongjihua.setMubiao(xingdongjihuaSubmitVo.getMubiao());
        xingdongjihua.setXingdong(xingdongjihuaSubmitVo.getXingdong());
        xingdongjihua.setXingdongTime(xingdongjihuaSubmitVo.getXingdongTime());
        xingdongjihua.setZhangai(xingdongjihuaSubmitVo.getZhangai());
        xingdongjihua.setYingdui(xingdongjihuaSubmitVo.getYingdui());
        xingdongjihua.setRecordId(-1);

        int res = xingdongjihuaMapper.insert(xingdongjihua);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

